package edu.fub.pub2search.app;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;


import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

/**
 * Class to manage the overlay of info status.
 * The goal is to show information about how many pubs are displayed.
 * 
 * @author Andrej
 */
public class InfoOverlay extends Overlay {

	/** For additional painting purposes. */
	private Paint innerPaint;
	private Paint borderPaint;
	private Paint textPaint;
		
	/** Variable for displayed string */
	private String infoStatus;
	
	/** 
	 * Constructor
	 * 
	 * @param infoStatus_ string which appear in infoStatus bar.
	 */
	public InfoOverlay(String infoStatus_){
		infoStatus = infoStatus_;
	}
	
	@Override
	public void draw(Canvas canvas, MapView	mapView, boolean shadow) {
		int INFO_STATUS_WIDTH = 60;
		int INFO_STATUS_HEGHT = 22;
		int MARGIN_SIZE = 5;
		
		// Create the rectangle label.
		RectF infoStatusRect = new RectF(0, 0, INFO_STATUS_WIDTH, INFO_STATUS_HEGHT);
		
		// Calculate rectangle's offset on the screen
		int infoStatusOffsetX = mapView.getWidth() - INFO_STATUS_WIDTH - MARGIN_SIZE;
		int infoStatusOffsetY = MARGIN_SIZE;
		
		// Set offset for object infoStatusRect:RectF
		infoStatusRect.offset(infoStatusOffsetX, infoStatusOffsetY);

		//  Draw inner for the name label
		canvas.drawRoundRect(infoStatusRect, 5, 5, getInnerPaint());
		
		//  Draw border for the name label
		canvas.drawRoundRect(infoStatusRect, 5, 5, getBorderPaint());
			
		//  Draw the infoStatus text
		int TEXT_OFFSET_X = 10;
		int TEXT_OFFSET_Y = 15;
		canvas.drawText(infoStatus, 
				infoStatusOffsetX + TEXT_OFFSET_X, 
				infoStatusOffsetY + TEXT_OFFSET_Y,
				getTextPaint());	
	}
	
// -------------------- PRIVATE METHODS ----------------------
	
	/*
	 * Configuration for background color
	 */
	private Paint getInnerPaint() {
		if (innerPaint == null) {
			innerPaint = new Paint();
			innerPaint.setARGB(40, 75, 75, 75); //grey
			innerPaint.setAntiAlias(true);
		}
		return innerPaint;
	}

	/*
	 * Configuration for border color
	 */
	private Paint getBorderPaint() {
		if (borderPaint == null) {
			borderPaint = new Paint();
			borderPaint.setARGB(255, 255, 255, 255);
			borderPaint.setAntiAlias(true);
			borderPaint.setStyle(Style.STROKE);
			borderPaint.setStrokeWidth(2);
		}
		return borderPaint;
	}

	/*
	 * Configuration for text color
	 */
	private Paint getTextPaint() {
		if (textPaint == null) {
			textPaint = new Paint();
			textPaint.setARGB(255, 255, 255, 255);
			textPaint.setAntiAlias(true);
		}
		return textPaint;
	}
}
